<template>
    <div class="app-container">
      <el-divider content-position="left">推荐课程</el-divider>
      <el-row :gutter="20">
        <el-col :span="8" v-for="(course) in recommendList" :key="course.courseId" style="margin-bottom: 24px;">
          <el-card :body-style="{ padding: '8px', border:'1px solid #13ce66'}" shadow="always">
            <el-row :gutter="4">
              <el-col :span="8">
                <el-image :src="course.courseImg">
                  <div slot="error" class="image-slot">
                    <i class="el-icon-picture-outline"></i>
                  </div>
                </el-image>
              </el-col>
              <el-col :span="16">
                <el-row style="margin-bottom: 8px;">
                  <el-col :span="24" style="font-weight: bold;">
                      <span>{{course.courseName}}</span>
                      <el-tag :type="course.referScore > 80 ? 'success':'warning'" style="float:right;">预测分数：<span style="font-size:24px;">{{course.referScore}}</span></el-tag>
                  </el-col>
                  <el-col :span="24" :class="{ 'multi-line-ellipsis': true }" :title="course.courseDesc">
                   {{ course.courseDesc }}
                  </el-col>
                </el-row>
                <el-row style="color:gray;font-size:12px;">
                  <el-col :span="12">授课教师：{{ course.courseLeader }}</el-col>
                  <el-col :span="12">课程学分：{{ course.courseScore  }}</el-col>
                  <el-col :span="12">课程时间：{{ course.courseTime  }} 学时</el-col>
                </el-row>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
      <el-divider content-position="left">全部课程</el-divider>
      <el-row :gutter="20">
        <el-col :span="8" v-for="(course) in courseList" :key="course.courseId" style="margin-bottom: 24px;">
          <el-card :body-style="{ padding: '8px' }" shadow="always">
            <el-row :gutter="4">
              <el-col :span="8">
                <el-image :src="course.courseImg">
                  <div slot="error" class="image-slot">
                    <i class="el-icon-picture-outline"></i>
                  </div>
                </el-image>
              </el-col>
              <el-col :span="16">
                <el-row style="margin-bottom: 8px;">
                  <el-col :span="24" style="font-weight: bold;">
                      <span>{{course.courseName}}</span>
                  </el-col>
                  <el-col :span="24" :class="{ 'multi-line-ellipsis': true }" :title="course.courseDesc">
                   {{ course.courseDesc }}
                  </el-col>
                </el-row>
                <el-row style="color:gray;font-size:12px;">
                  <el-col :span="12">授课教师：{{ course.courseLeader }}</el-col>
                  <el-col :span="12">课程学分：{{ course.courseScore  }}</el-col>
                  <el-col :span="12">课程时间：{{ course.courseTime  }} 学时</el-col>
                </el-row>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getAllCourseList"
        />
    </div>
  </template>
  
  <script>
  import { listRecommendFull } from "@/api/courseSelect/recommend";
  import { listCourse } from "@/api/courseSelect/course";
  
  export default {
    name: "Recommend",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 课程推荐表格数据
        recommendList: [],
        courseList:[],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          studentClass: null,
          studentId: null,
          studentName: null,
          courseId: null,
          courseName: null,
          referScore: null,
          semester: null,
          STATUS: null,
          remark: null
        },
      };
    },
    created() {
      this.getRecommendList();
      this.getAllCourseList();
    },
    methods: {
      /** 查询课程推荐列表 */
      getRecommendList() {
        this.loading = true;
        listRecommendFull().then(response => {
          this.recommendList = response.rows;
          this.recommendList.forEach(course => {
            if(course.courseImg && course.courseImg.length>0) {
              course.courseImg = course.courseImg.split(",")[0];
            }
          });
          this.loading = false;
        });
      },

       /** 查询所有课程列表 */
       getAllCourseList() {
        this.loading = true;
        listCourse(this.queryParams).then(response => {
          this.courseList = response.rows;
          this.courseList.forEach(course => {
            if(course.courseImg && course.courseImg.length>0) {
              course.courseImg = course.courseImg.split(",")[0];
            }
          });
          this.total = response.total;
          this.loading = false;
        });
      },
    }
  };
  </script>

  <style scoped>
    .multi-line-ellipsis {  
      display: -webkit-box;  
      -webkit-box-orient: vertical;  
      -webkit-line-clamp: 2; /* 限制显示的行数 */  
      overflow: hidden;  
      font-size: 14px;
      color:gray;
      min-height: 32px;
    }  
  </style>
  